home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / amok98-106 / amok98 / programminginoberon / frects1.mod < prev    next >
Text File  |  1993-10-07  |  1KB  |  42 lines

  1. MODULE FilledRects;
  2. (* Extension of very tiny graphics editor, Exercise 12.7, page 242.
  3.     Note: In Programming in Oberon, this module is called FilledRectangles. It
  4.     is renamed to avoid naming conflict with the standard Draw package *)
  5.  
  6. IMPORT Graphs, Rects, Display;
  7. CONST white = Display.white;  repl = Display.replace;
  8. TYPE 
  9.     FilledRect* = POINTER TO RectDesc;
  10.     RectDesc* = RECORD(Rects.RectDesc)    
  11.         pat*: Display.Pattern
  12.     END;
  13.  
  14. PROCEDURE Min(x, y: INTEGER): INTEGER;
  15. BEGIN IF x < y THEN RETURN x ELSE RETURN y END
  16. END Min;
  17.  
  18. PROCEDURE Draw*(r: Graphs.Figure);
  19. BEGIN
  20.     WITH r: FilledRect DO 
  21.         Rects.Draw(r);
  22.         Display.ReplPattern(white, r.pat, r.x+1, r.y + 1, r.w - 2, r.h - 2, repl)
  23.     END
  24. END Draw;
  25.  
  26. PROCEDURE NewFigure*(): Graphs.Figure;
  27. VAR r: FilledRect;  x1, y1, x2, y2: INTEGER;  
  28. BEGIN
  29.     NEW(r);  
  30.     r.draw := Draw;  
  31.     r.pat := Display.grey0;  (* light grey pattern *)
  32.     Graphs.spanVect(x1, y1, x2, y2);
  33.     r.x := Min(x1, x2);  r.y := Min(y1, y2);  
  34.     r.w := ABS(x2 - x1);  r.h := ABS(y2 - y1);
  35.     RETURN r
  36. END NewFigure;
  37.  
  38. PROCEDURE Set*;
  39. BEGIN  Graphs.newFigure := NewFigure;
  40. END Set;
  41.  
  42. END FilledRects.    (* Copyright M. Reiser, 1992 *)